import time


class People:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def __str__(self):
        # 对象被打印时自动触发，可以用来定义对象被打印时的输出信息
        return "<name:%s age %s>"%(self.name,self.age)
    def run(self):
        return self.name
"""obj = People("长帅",18)
print(obj)
print(obj.run())"""
class Foo:
    def __init__(self,x,filepath,encoding = 'utf-8'):
        self.x = x
        self.f = open(filepath,'r',encoding=encoding)
    def __del__(self):
        # 在对象被删除时先自动触发该方法，可以用来回收对象以外其他相关资管，比如系统资源
        print("__del__正在运行")
        self.f.close()
        del self.x
obj = Foo(1,'a.txt')
print(obj.f.read())
time.sleep(3)
# obj.f.close()
print(obj.f.read())






class Foo1:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def __call__(self, *args, **kwargs):
        print(self,args,kwargs)
    def run(self):
        print("run")
"""obj1 = Foo1("张三",19)
obj1.run()
obj1(1,2,3,4,5,姓名="王五",地址="辽宁沈阳")"""

# 字典 kwagrs 直接就带了双引号了

# 字典里面可以当作key的原因： 都是不可变对象
# print({1: "数字当作key", "数字": "数字", (1,): "数字1"})

# 不可变的对象不能当作key
# print({[1,2,3]:"数字",{1,2,3}:"集合"})

def content(*args,**kwargs):
    """
    :param args: 不定长参数
    :param kwargs: 不定长关键字参数
    :return:
    """
    print(args) # (1,2,3,4,5,[1,2,3],{1,2,3},(1,2,3),{"aa":"bb"})
    print(kwargs) #  {"姓名":"张三"}
# content(1,2,3,4,5,[1,2,3],{1,2,3},(1,2,3),{"aa":"bb"},姓名="张三")


